package cn.fj.hrm.controller;

import cn.fj.hrm.basic.constant.MQContant;
import cn.fj.hrm.basic.util.JsonResult;
import cn.fj.hrm.domain.Msg;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/msgSender")
public class MsgSenderController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送消息到消息队列的公共接口
     * @param msg
     * @return
     */
    @PostMapping("/send")
    public JsonResult sendMsg(@RequestBody Msg msg){
        System.out.println("正在推送消息:" + msg);
        rabbitTemplate.convertAndSend(MQContant.EXCHANGE_HRM_TOPIC, msg.getRoutingkey(), msg);
        return JsonResult.me();
    }


}
